import 'package:hxdj/common/base_page/base_page.dart';
import 'package:hxdj/common/dio/dio_http.dart';
import 'package:hxdj/common/dio/my_api.dart';
import 'package:hxdj/home/address/select_address/address_model.dart';

class SelectAddressViewModel extends BaseViewModel {
  List<AddressModel> addressModelsDataList = [];
  //请求数据
  @override
  requestData({Function(dynamic)? onSuccess, Function(dynamic)? onError}) async {
    setState(ViewState.loading);
    addressModelsDataList.clear();
    // 去请求服务器数据.
    Map<String, dynamic> resultMap = await DioHttpManager().request(MyApi.memberAdds, method: DioHttpManager.post);
    // 请求成功后, 更新页面.
    if (resultMap['code'] == 0) {
      List<dynamic> addressDataList = resultMap['data']['list'] ?? [{}];
      for (Map<String, dynamic> element in addressDataList) {
        //是否是默认地址 1：默认地址 2：不是
        addressModelsDataList.add(AddressModel.fromMap(element));
      }
    }

    // 更新页面.
    setState(ViewState.normal);
  }
}
